package _5_chain_of_responsibility

import "strings"

type CheckBody struct {
	body string
}

type Checker interface {
	check(body CheckBody) bool
}

type CheckerChain struct {
	checkers []Checker
}

func (c *CheckerChain) AddChecker(checker Checker) {
	c.checkers = append(c.checkers, checker)
}

func (c *CheckerChain) check(body CheckBody) bool {
	for _, checker := range c.checkers {
		if !checker.check(body) {
			return false
		}
	}
	return true
}

type AChecker struct {
}

func (A *AChecker) check(body CheckBody) bool {
	return strings.Contains(body.body, "a")
}

type BChecker struct {
}

func (B *BChecker) check(body CheckBody) bool {
	return strings.Contains(body.body, "b")
}
